using System;
using System.Collections.Generic;
using System.Text;

namespace DiscuzRobot
{
    public  class SiteInfo
    {
        private string siteName, siteUrl, logoUrl, userName, userPwd, configpath;
        private bool getDoucmentByAppRun, logonDefaultUserByAppRun;

        public bool LogonDefaultUserByAppRun
        {
            get { return logonDefaultUserByAppRun; }
            set { logonDefaultUserByAppRun = value; }
        }

        public bool GetDoucmentByAppRun
        {
            get { return getDoucmentByAppRun; }
            set { getDoucmentByAppRun = value; }
        }
        public string SiteName
        {
            get { return siteName; }
            set { siteName = value; }
        }

        private static SiteInfo instance;

        public static SiteInfo Instance
        {
            get {
                if (instance == null)
                {
                    instance = new SiteInfo();
                    instance.Initial();
                }
                return instance;
            }
            //set { SiteInfo.instance = value; }
        }

        public SiteInfo()
        {
            //this.configpath = configph;
            //instance.Initial();
        }
        public void Initial()
        {
            RWIniFile rini = new RWIniFile(Global.APP_ConfigPath);
            this.siteName = rini.ReadValue("site", "siteName");
            
            this.siteUrl = rini.ReadValue("site", "siteurl");
            if (this.siteUrl[this.siteUrl.Length - 1] != '/')
                this.siteUrl += "/";

            this.logoUrl = rini.ReadValue("site", "logoUrl");
            this.userName = rini.ReadValue("site", "userName");
            this.userPwd = rini.ReadValue("site", "userPwd");
            this.getDoucmentByAppRun = bool.Parse(rini.ReadValue("site", "getDoucmentByAppRun"));
            this.logonDefaultUserByAppRun = bool.Parse(rini.ReadValue("site", "logonDefaultUserByAppRun"));
        }
        public void SaveConfig()
        {
            RWIniFile rini = new RWIniFile(Global.APP_ConfigPath);
            rini.Writue("site", "siteName", this.siteName);
            rini.Writue("site", "siteurl", this.siteUrl);

            rini.Writue("site", "logoUrl", this.logoUrl);
            rini.Writue("site", "userName", this.userName);
            rini.Writue("site", "userPwd", this.userPwd);

            rini.Writue("site", "getDoucmentByAppRun", this.getDoucmentByAppRun.ToString());
            rini.Writue("site", "logonDefaultUserByAppRun", this.logonDefaultUserByAppRun.ToString());


        }
        public string UserPwd
        {
            get { return userPwd; }
            set { userPwd = value; }
        }

        public string UserName
        {
            get { return userName; }
            set { userName = value; }
        }

        public string LogoUrl
        {
            get { return logoUrl; }
            set { logoUrl = value; }
        }

        public string StieUrl
        {
            get { return siteUrl; }
            set { siteUrl = value; }
        }
    }
}
